explicit operator bool() const noexcept;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// example of shared_ptr::operator bool
#include <iostream>
#include <memory>
int main () {
std::shared_ptr<int> foo;
std::shared_ptr<int> bar (new int(34));
if (foo) std::cout << "foo points to " << *foo << '\n';
else std::cout << "foo is null\n";
if (bar) std::cout << "bar points to " << *bar << '\n';
else std::cout << "bar is null\n";
return 0;
}
foo is null bar points to 34